home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / info / lispref.info-7.z / lispref.info-7
Encoding:
GNU Info File  |  1998-05-21  |  50.1 KB  |  1,282 lines

  1. This is Info file ../../info/lispref.info, produced by Makeinfo version
  2. 1.68 from the input file lispref.texi.
  3.  
  4.    Edition History:
  5.  
  6.    GNU Emacs Lisp Reference Manual Second Edition (v2.01), May 1993 GNU
  7. Emacs Lisp Reference Manual Further Revised (v2.02), August 1993 Lucid
  8. Emacs Lisp Reference Manual (for 19.10) First Edition, March 1994
  9. XEmacs Lisp Programmer's Manual (for 19.12) Second Edition, April 1995
  10. GNU Emacs Lisp Reference Manual v2.4, June 1995 XEmacs Lisp
  11. Programmer's Manual (for 19.13) Third Edition, July 1995 XEmacs Lisp
  12. Reference Manual (for 19.14 and 20.0) v3.1, March 1996 XEmacs Lisp
  13. Reference Manual (for 19.15 and 20.1, 20.2) v3.2, April, May 1997
  14.  
  15.    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software
  16. Foundation, Inc.  Copyright (C) 1994, 1995 Sun Microsystems, Inc.
  17. Copyright (C) 1995, 1996 Ben Wing.
  18.  
  19.    Permission is granted to make and distribute verbatim copies of this
  20. manual provided the copyright notice and this permission notice are
  21. preserved on all copies.
  22.  
  23.    Permission is granted to copy and distribute modified versions of
  24. this manual under the conditions for verbatim copying, provided that the
  25. entire resulting derived work is distributed under the terms of a
  26. permission notice identical to this one.
  27.  
  28.    Permission is granted to copy and distribute translations of this
  29. manual into another language, under the above conditions for modified
  30. versions, except that this permission notice may be stated in a
  31. translation approved by the Foundation.
  32.  
  33.    Permission is granted to copy and distribute modified versions of
  34. this manual under the conditions for verbatim copying, provided also
  35. that the section entitled "GNU General Public License" is included
  36. exactly as in the original, and provided that the entire resulting
  37. derived work is distributed under the terms of a permission notice
  38. identical to this one.
  39.  
  40.    Permission is granted to copy and distribute translations of this
  41. manual into another language, under the above conditions for modified
  42. versions, except that the section entitled "GNU General Public License"
  43. may be included in a translation approved by the Free Software
  44. Foundation instead of in the original English.
  45.  
  46. 
  47. File: lispref.info,  Node: Sequence Functions,  Next: Arrays,  Up: Sequences Arrays Vectors
  48.  
  49. Sequences
  50. =========
  51.  
  52.    In XEmacs Lisp, a "sequence" is either a list, a vector, a bit
  53. vector, or a string.  The common property that all sequences have is
  54. that each is an ordered collection of elements.  This section describes
  55. functions that accept any kind of sequence.
  56.  
  57.  - Function: sequencep OBJECT
  58.      Returns `t' if OBJECT is a list, vector, bit vector, or string,
  59.      `nil' otherwise.
  60.  
  61.  - Function: copy-sequence SEQUENCE
  62.      Returns a copy of SEQUENCE.  The copy is the same type of object
  63.      as the original sequence, and it has the same elements in the same
  64.      order.
  65.  
  66.      Storing a new element into the copy does not affect the original
  67.      SEQUENCE, and vice versa.  However, the elements of the new
  68.      sequence are not copies; they are identical (`eq') to the elements
  69.      of the original.  Therefore, changes made within these elements, as
  70.      found via the copied sequence, are also visible in the original
  71.      sequence.
  72.  
  73.      If the sequence is a string with extents or text properties, the
  74.      extents and text properties in the copy are also copied, not
  75.      shared with the original. (This means that modifying the extents
  76.      or text properties of the original will not affect the copy.)
  77.      However, the actual values of the properties are shared.  *Note
  78.      Extents::; *Note Text Properties::.
  79.  
  80.      See also `append' in *Note Building Lists::, `concat' in *Note
  81.      Creating Strings::, `vconcat' in *Note Vectors::, and `bvconcat'
  82.      in *Note Bit Vectors::, for other ways to copy sequences.
  83.  
  84.           (setq bar '(1 2))
  85.                => (1 2)
  86.           (setq x (vector 'foo bar))
  87.                => [foo (1 2)]
  88.           (setq y (copy-sequence x))
  89.                => [foo (1 2)]
  90.           
  91.           (eq x y)
  92.                => nil
  93.           (equal x y)
  94.                => t
  95.           (eq (elt x 1) (elt y 1))
  96.                => t
  97.           
  98.           ;; Replacing an element of one sequence.
  99.           (aset x 0 'quux)
  100.           x => [quux (1 2)]
  101.           y => [foo (1 2)]
  102.           
  103.           ;; Modifying the inside of a shared element.
  104.           (setcar (aref x 1) 69)
  105.           x => [quux (69 2)]
  106.           y => [foo (69 2)]
  107.           
  108.           ;; Creating a bit vector.
  109.           (bit-vector 1 0 1 1 0 1 0 0)
  110.                => #*10110100
  111.  
  112.  - Function: length SEQUENCE
  113.      Returns the number of elements in SEQUENCE.  If SEQUENCE is a cons
  114.      cell that is not a list (because the final CDR is not `nil'), a
  115.      `wrong-type-argument' error is signaled.
  116.  
  117.           (length '(1 2 3))
  118.               => 3
  119.           (length ())
  120.               => 0
  121.           (length "foobar")
  122.               => 6
  123.           (length [1 2 3])
  124.               => 3
  125.           (length #*01101)
  126.               => 5
  127.  
  128.  - Function: elt SEQUENCE INDEX
  129.      This function returns the element of SEQUENCE indexed by INDEX.
  130.      Legitimate values of INDEX are integers ranging from 0 up to one
  131.      less than the length of SEQUENCE.  If SEQUENCE is a list, then
  132.      out-of-range values of INDEX return `nil'; otherwise, they trigger
  133.      an `args-out-of-range' error.
  134.  
  135.           (elt [1 2 3 4] 2)
  136.                => 3
  137.           (elt '(1 2 3 4) 2)
  138.                => 3
  139.           (char-to-string (elt "1234" 2))
  140.                => "3"
  141.           (elt #*00010000 3)
  142.                => 1
  143.           (elt [1 2 3 4] 4)
  144.                error-->Args out of range: [1 2 3 4], 4
  145.           (elt [1 2 3 4] -1)
  146.                error-->Args out of range: [1 2 3 4], -1
  147.  
  148.      This function generalizes `aref' (*note Array Functions::.) and
  149.      `nth' (*note List Elements::.).
  150.  
  151. 
  152. File: lispref.info,  Node: Arrays,  Next: Array Functions,  Prev: Sequence Functions,  Up: Sequences Arrays Vectors
  153.  
  154. Arrays
  155. ======
  156.  
  157.    An "array" object has slots that hold a number of other Lisp
  158. objects, called the elements of the array.  Any element of an array may
  159. be accessed in constant time.  In contrast, an element of a list
  160. requires access time that is proportional to the position of the element
  161. in the list.
  162.  
  163.    When you create an array, you must specify how many elements it has.
  164. The amount of space allocated depends on the number of elements.
  165. Therefore, it is impossible to change the size of an array once it is
  166. created; you cannot add or remove elements.  However, you can replace an
  167. element with a different value.
  168.  
  169.    XEmacs defines three types of array, all of which are
  170. one-dimensional: "strings", "vectors", and "bit vectors".  A vector is a
  171. general array; its elements can be any Lisp objects.  A string is a
  172. specialized array; its elements must be characters.  A bit vector is
  173. another specialized array; its elements must be bits (an integer, either
  174. 0 or 1).  Each type of array has its own read syntax.  *Note String
  175. Type::, *Note Vector Type::, and *Note Bit Vector Type::.
  176.  
  177.    All kinds of array share these characteristics:
  178.  
  179.    * The first element of an array has index zero, the second element
  180.      has index 1, and so on.  This is called "zero-origin" indexing.
  181.      For example, an array of four elements has indices 0, 1, 2, and 3.
  182.  
  183.    * The elements of an array may be referenced or changed with the
  184.      functions `aref' and `aset', respectively (*note Array
  185.      Functions::.).
  186.  
  187.    In principle, if you wish to have an array of text characters, you
  188. could use either a string or a vector.  In practice, we always choose
  189. strings for such applications, for four reasons:
  190.  
  191.    * They usually occupy one-fourth the space of a vector of the same
  192.      elements.  (This is one-eighth the space for 64-bit machines such
  193.      as the DEC Alpha, and may also be different when MULE support is
  194.      compiled into XEmacs.)
  195.  
  196.    * Strings are printed in a way that shows the contents more clearly
  197.      as characters.
  198.  
  199.    * Strings can hold extent and text properties.  *Note Extents::;
  200.      *Note Text Properties::.
  201.  
  202.    * Many of the specialized editing and I/O facilities of XEmacs
  203.      accept only strings.  For example, you cannot insert a vector of
  204.      characters into a buffer the way you can insert a string.  *Note
  205.      Strings and Characters::.
  206.  
  207.    By contrast, for an array of keyboard input characters (such as a key
  208. sequence), a vector may be necessary, because many keyboard input
  209. characters are non-printable and are represented with symbols rather
  210. than with characters.  *Note Key Sequence Input::.
  211.  
  212.    Similarly, when representing an array of bits, a bit vector has the
  213. following advantages over a regular vector:
  214.  
  215.    * They occupy 1/32nd the space of a vector of the same elements.
  216.      (1/64th on 64-bit machines such as the DEC Alpha.)
  217.  
  218.    * Bit vectors are printed in a way that shows the contents more
  219.      clearly as bits.
  220.  
  221. 
  222. File: lispref.info,  Node: Array Functions,  Next: Vectors,  Prev: Arrays,  Up: Sequences Arrays Vectors
  223.  
  224. Functions that Operate on Arrays
  225. ================================
  226.  
  227.    In this section, we describe the functions that accept strings,
  228. vectors, and bit vectors.
  229.  
  230.  - Function: arrayp OBJECT
  231.      This function returns `t' if OBJECT is an array (i.e., a string,
  232.      vector, or bit vector).
  233.  
  234.           (arrayp "asdf")
  235.           => t
  236.           (arrayp [a])
  237.           => t
  238.           (arrayp #*101)
  239.           => t
  240.  
  241.  - Function: aref ARRAY INDEX
  242.      This function returns the INDEXth element of ARRAY.  The first
  243.      element is at index zero.
  244.  
  245.           (setq primes [2 3 5 7 11 13])
  246.                => [2 3 5 7 11 13]
  247.           (aref primes 4)
  248.                => 11
  249.           (elt primes 4)
  250.                => 11
  251.           
  252.           (aref "abcdefg" 1)
  253.                => ?b
  254.           
  255.           (aref #*1101 2)
  256.                => 0
  257.  
  258.      See also the function `elt', in *Note Sequence Functions::.
  259.  
  260.  - Function: aset ARRAY INDEX OBJECT
  261.      This function sets the INDEXth element of ARRAY to be OBJECT.  It
  262.      returns OBJECT.
  263.  
  264.           (setq w [foo bar baz])
  265.                => [foo bar baz]
  266.           (aset w 0 'fu)
  267.                => fu
  268.           w
  269.                => [fu bar baz]
  270.           
  271.           (setq x "asdfasfd")
  272.                => "asdfasfd"
  273.           (aset x 3 ?Z)
  274.                => ?Z
  275.           x
  276.                => "asdZasfd"
  277.           
  278.           (setq bv #*1111)
  279.                => #*1111
  280.           (aset bv 2 0)
  281.                => 0
  282.           bv
  283.                => #*1101
  284.  
  285.      If ARRAY is a string and OBJECT is not a character, a
  286.      `wrong-type-argument' error results.
  287.  
  288.  - Function: fillarray ARRAY OBJECT
  289.      This function fills the array ARRAY with OBJECT, so that each
  290.      element of ARRAY is OBJECT.  It returns ARRAY.
  291.  
  292.           (setq a [a b c d e f g])
  293.                => [a b c d e f g]
  294.           (fillarray a 0)
  295.                => [0 0 0 0 0 0 0]
  296.           a
  297.                => [0 0 0 0 0 0 0]
  298.           
  299.           (setq s "When in the course")
  300.                => "When in the course"
  301.           (fillarray s ?-)
  302.                => "------------------"
  303.           
  304.           (setq bv #*1101)
  305.                => #*1101
  306.           (fillarray bv 0)
  307.                => #*0000
  308.  
  309.      If ARRAY is a string and OBJECT is not a character, a
  310.      `wrong-type-argument' error results.
  311.  
  312.    The general sequence functions `copy-sequence' and `length' are
  313. often useful for objects known to be arrays.  *Note Sequence
  314. Functions::.
  315.  
  316. 
  317. File: lispref.info,  Node: Vectors,  Next: Vector Functions,  Prev: Array Functions,  Up: Sequences Arrays Vectors
  318.  
  319. Vectors
  320. =======
  321.  
  322.    Arrays in Lisp, like arrays in most languages, are blocks of memory
  323. whose elements can be accessed in constant time.  A "vector" is a
  324. general-purpose array; its elements can be any Lisp objects.  (The other
  325. kind of array in XEmacs Lisp is the "string", whose elements must be
  326. characters.)  Vectors in XEmacs serve as obarrays (vectors of symbols),
  327. although this is a shortcoming that should be fixed.  They are also used
  328. internally as part of the representation of a byte-compiled function; if
  329. you print such a function, you will see a vector in it.
  330.  
  331.    In XEmacs Lisp, the indices of the elements of a vector start from
  332. zero and count up from there.
  333.  
  334.    Vectors are printed with square brackets surrounding the elements.
  335. Thus, a vector whose elements are the symbols `a', `b' and `a' is
  336. printed as `[a b a]'.  You can write vectors in the same way in Lisp
  337. input.
  338.  
  339.    A vector, like a string or a number, is considered a constant for
  340. evaluation: the result of evaluating it is the same vector.  This does
  341. not evaluate or even examine the elements of the vector.  *Note
  342. Self-Evaluating Forms::.
  343.  
  344.    Here are examples of these principles:
  345.  
  346.      (setq avector [1 two '(three) "four" [five]])
  347.           => [1 two (quote (three)) "four" [five]]
  348.      (eval avector)
  349.           => [1 two (quote (three)) "four" [five]]
  350.      (eq avector (eval avector))
  351.           => t
  352.  
  353. 
  354. File: lispref.info,  Node: Vector Functions,  Next: Bit Vectors,  Prev: Vectors,  Up: Sequences Arrays Vectors
  355.  
  356. Functions That Operate on Vectors
  357. =================================
  358.  
  359.    Here are some functions that relate to vectors:
  360.  
  361.  - Function: vectorp OBJECT
  362.      This function returns `t' if OBJECT is a vector.
  363.  
  364.           (vectorp [a])
  365.                => t
  366.           (vectorp "asdf")
  367.                => nil
  368.  
  369.  - Function: vector &rest OBJECTS
  370.      This function creates and returns a vector whose elements are the
  371.      arguments, OBJECTS.
  372.  
  373.           (vector 'foo 23 [bar baz] "rats")
  374.                => [foo 23 [bar baz] "rats"]
  375.           (vector)
  376.                => []
  377.  
  378.  - Function: make-vector LENGTH OBJECT
  379.      This function returns a new vector consisting of LENGTH elements,
  380.      each initialized to OBJECT.
  381.  
  382.           (setq sleepy (make-vector 9 'Z))
  383.                => [Z Z Z Z Z Z Z Z Z]
  384.  
  385.  - Function: vconcat &rest SEQUENCES
  386.      This function returns a new vector containing all the elements of
  387.      the SEQUENCES.  The arguments SEQUENCES may be lists, vectors, or
  388.      strings.  If no SEQUENCES are given, an empty vector is returned.
  389.  
  390.      The value is a newly constructed vector that is not `eq' to any
  391.      existing vector.
  392.  
  393.           (setq a (vconcat '(A B C) '(D E F)))
  394.                => [A B C D E F]
  395.           (eq a (vconcat a))
  396.                => nil
  397.           (vconcat)
  398.                => []
  399.           (vconcat [A B C] "aa" '(foo (6 7)))
  400.                => [A B C 97 97 foo (6 7)]
  401.  
  402.      The `vconcat' function also allows integers as arguments.  It
  403.      converts them to strings of digits, making up the decimal print
  404.      representation of the integer, and then uses the strings instead
  405.      of the original integers.  *Don't use this feature; we plan to
  406.      eliminate it.  If you already use this feature, change your
  407.      programs now!*  The proper way to convert an integer to a decimal
  408.      number in this way is with `format' (*note Formatting Strings::.)
  409.      or `number-to-string' (*note String Conversion::.).
  410.  
  411.      For other concatenation functions, see `mapconcat' in *Note
  412.      Mapping Functions::, `concat' in *Note Creating Strings::, `append'
  413.      in *Note Building Lists::, and `bvconcat' in *Note Bit Vector
  414.      Functions::.
  415.  
  416.    The `append' function provides a way to convert a vector into a list
  417. with the same elements (*note Building Lists::.):
  418.  
  419.      (setq avector [1 two (quote (three)) "four" [five]])
  420.           => [1 two (quote (three)) "four" [five]]
  421.      (append avector nil)
  422.           => (1 two (quote (three)) "four" [five])
  423.  
  424. 
  425. File: lispref.info,  Node: Bit Vectors,  Next: Bit Vector Functions,  Prev: Vector Functions,  Up: Sequences Arrays Vectors
  426.  
  427. Bit Vectors
  428. ===========
  429.  
  430.    Bit vectors are specialized vectors that can only represent arrays
  431. of 1's and 0's.  Bit vectors have a very efficient representation and
  432. are useful for representing sets of boolean (true or false) values.
  433.  
  434.    There is no limit on the size of a bit vector.  You could, for
  435. example, create a bit vector with 100,000 elements if you really wanted
  436. to.
  437.  
  438.    Bit vectors have a special printed representation consisting of `#*'
  439. followed by the bits of the vector.  For example, a bit vector whose
  440. elements are 0, 1, 1, 0, and 1, respectively, is printed as
  441.  
  442.      #*01101
  443.  
  444.    Bit vectors are considered constants for evaluation, like vectors,
  445. strings, and numbers.  *Note Self-Evaluating Forms::.
  446.  
  447. 
  448. File: lispref.info,  Node: Bit Vector Functions,  Prev: Bit Vectors,  Up: Sequences Arrays Vectors
  449.  
  450. Functions That Operate on Bit Vectors
  451. =====================================
  452.  
  453.    Here are some functions that relate to bit vectors:
  454.  
  455.  - Function: bit-vector-p OBJECT
  456.      This function returns `t' if OBJECT is a bit vector.
  457.  
  458.           (bit-vector-p #*01)
  459.                => t
  460.           (bit-vector-p [0 1])
  461.                => nil
  462.           (bit-vector-p "01")
  463.                => nil
  464.  
  465.  - Function: bitp OBJECT
  466.      This function returns `t' if OBJECT is either 0 or 1.
  467.  
  468.  - Function: bit-vector &rest OBJECTS
  469.      This function creates and returns a bit vector whose elements are
  470.      the arguments OBJECTS.  The elements must be either of the two
  471.      integers 0 or 1.
  472.  
  473.           (bit-vector 0 0 0 1 0 0 0 0 1 0)
  474.                => #*0001000010
  475.           (bit-vector)
  476.                => #*
  477.  
  478.  - Function: make-bit-vector LENGTH OBJECT
  479.      This function creates and returns a bit vector consisting of
  480.      LENGTH elements, each initialized to OBJECT.
  481.  
  482.           (setq picket-fence (make-bit-vector 9 1))
  483.                => #*111111111
  484.  
  485.  - Function: bvconcat &rest SEQUENCES
  486.      This function returns a new bit vector containing all the elements
  487.      of the SEQUENCES.  The arguments SEQUENCES may be lists, vectors,
  488.      or bit vectors, all of whose elements are the integers 0 or 1.  If
  489.      no SEQUENCES are given, an empty bit vector is returned.
  490.  
  491.      The value is a newly constructed bit vector that is not `eq' to any
  492.      existing bit vector.
  493.  
  494.           (setq a (bvconcat '(1 1 0) '(0 0 1)))
  495.                => #*110001
  496.           (eq a (bvconcat a))
  497.                => nil
  498.           (bvconcat)
  499.                => #*
  500.           (bvconcat [1 0 0 0 0] #*111 '(0 0 0 0 1))
  501.                => #*1000011100001
  502.  
  503.      For other concatenation functions, see `mapconcat' in *Note
  504.      Mapping Functions::, `concat' in *Note Creating Strings::,
  505.      `vconcat' in *Note Vector Functions::, and `append' in *Note
  506.      Building Lists::.
  507.  
  508.    The `append' function provides a way to convert a bit vector into a
  509. list with the same elements (*note Building Lists::.):
  510.  
  511.      (setq bv #*00001110)
  512.           => #*00001110
  513.      (append bv nil)
  514.           => (0 0 0 0 1 1 1 0)
  515.  
  516. 
  517. File: lispref.info,  Node: Symbols,  Next: Evaluation,  Prev: Sequences Arrays Vectors,  Up: Top
  518.  
  519. Symbols
  520. *******
  521.  
  522.    A "symbol" is an object with a unique name.  This chapter describes
  523. symbols, their components, their property lists, and how they are
  524. created and interned.  Separate chapters describe the use of symbols as
  525. variables and as function names; see *Note Variables::, and *Note
  526. Functions::.  For the precise read syntax for symbols, see *Note Symbol
  527. Type::.
  528.  
  529.    You can test whether an arbitrary Lisp object is a symbol with
  530. `symbolp':
  531.  
  532.  - Function: symbolp OBJECT
  533.      This function returns `t' if OBJECT is a symbol, `nil' otherwise.
  534.  
  535. * Menu:
  536.  
  537. * Symbol Components::       Symbols have names, values, function definitions
  538.                               and property lists.
  539. * Definitions::             A definition says how a symbol will be used.
  540. * Creating Symbols::        How symbols are kept unique.
  541. * Symbol Properties::       Each symbol has a property list
  542.                               for recording miscellaneous information.
  543.  
  544. 
  545. File: lispref.info,  Node: Symbol Components,  Next: Definitions,  Up: Symbols
  546.  
  547. Symbol Components
  548. =================
  549.  
  550.    Each symbol has four components (or "cells"), each of which
  551. references another object:
  552.  
  553. Print name
  554.      The "print name cell" holds a string that names the symbol for
  555.      reading and printing.  See `symbol-name' in *Note Creating
  556.      Symbols::.
  557.  
  558. Value
  559.      The "value cell" holds the current value of the symbol as a
  560.      variable.  When a symbol is used as a form, the value of the form
  561.      is the contents of the symbol's value cell.  See `symbol-value' in
  562.      *Note Accessing Variables::.
  563.  
  564. Function
  565.      The "function cell" holds the function definition of the symbol.
  566.      When a symbol is used as a function, its function definition is
  567.      used in its place.  This cell is also used to make a symbol stand
  568.      for a keymap or a keyboard macro, for editor command execution.
  569.      Because each symbol has separate value and function cells,
  570.      variables and function names do not conflict.  See
  571.      `symbol-function' in *Note Function Cells::.
  572.  
  573. Property list
  574.      The "property list cell" holds the property list of the symbol.
  575.      See `symbol-plist' in *Note Symbol Properties::.
  576.  
  577.    The print name cell always holds a string, and cannot be changed.
  578. The other three cells can be set individually to any specified Lisp
  579. object.
  580.  
  581.    The print name cell holds the string that is the name of the symbol.
  582. Since symbols are represented textually by their names, it is important
  583. not to have two symbols with the same name.  The Lisp reader ensures
  584. this: every time it reads a symbol, it looks for an existing symbol with
  585. the specified name before it creates a new one.  (In XEmacs Lisp, this
  586. lookup uses a hashing algorithm and an obarray; see *Note Creating
  587. Symbols::.)
  588.  
  589.    In normal usage, the function cell usually contains a function or
  590. macro, as that is what the Lisp interpreter expects to see there (*note
  591. Evaluation::.).  Keyboard macros (*note Keyboard Macros::.), keymaps
  592. (*note Keymaps::.) and autoload objects (*note Autoloading::.) are also
  593. sometimes stored in the function cell of symbols.  We often refer to
  594. "the function `foo'" when we really mean the function stored in the
  595. function cell of the symbol `foo'.  We make the distinction only when
  596. necessary.
  597.  
  598.    The property list cell normally should hold a correctly formatted
  599. property list (*note Property Lists::.), as a number of functions expect
  600. to see a property list there.
  601.  
  602.    The function cell or the value cell may be "void", which means that
  603. the cell does not reference any object.  (This is not the same thing as
  604. holding the symbol `void', nor the same as holding the symbol `nil'.)
  605. Examining a cell that is void results in an error, such as `Symbol's
  606. value as variable is void'.
  607.  
  608.    The four functions `symbol-name', `symbol-value', `symbol-plist',
  609. and `symbol-function' return the contents of the four cells of a
  610. symbol.  Here as an example we show the contents of the four cells of
  611. the symbol `buffer-file-name':
  612.  
  613.      (symbol-name 'buffer-file-name)
  614.           => "buffer-file-name"
  615.      (symbol-value 'buffer-file-name)
  616.           => "/gnu/elisp/symbols.texi"
  617.      (symbol-plist 'buffer-file-name)
  618.           => (variable-documentation 29529)
  619.      (symbol-function 'buffer-file-name)
  620.           => #<subr buffer-file-name>
  621.  
  622. Because this symbol is the variable which holds the name of the file
  623. being visited in the current buffer, the value cell contents we see are
  624. the name of the source file of this chapter of the XEmacs Lisp Manual.
  625. The property list cell contains the list `(variable-documentation
  626. 29529)' which tells the documentation functions where to find the
  627. documentation string for the variable `buffer-file-name' in the `DOC'
  628. file.  (29529 is the offset from the beginning of the `DOC' file to
  629. where that documentation string begins.)  The function cell contains
  630. the function for returning the name of the file.  `buffer-file-name'
  631. names a primitive function, which has no read syntax and prints in hash
  632. notation (*note Primitive Function Type::.).  A symbol naming a
  633. function written in Lisp would have a lambda expression (or a byte-code
  634. object) in this cell.
  635.  
  636. 
  637. File: lispref.info,  Node: Definitions,  Next: Creating Symbols,  Prev: Symbol Components,  Up: Symbols
  638.  
  639. Defining Symbols
  640. ================
  641.  
  642.    A "definition" in Lisp is a special form that announces your
  643. intention to use a certain symbol in a particular way.  In XEmacs Lisp,
  644. you can define a symbol as a variable, or define it as a function (or
  645. macro), or both independently.
  646.  
  647.    A definition construct typically specifies a value or meaning for the
  648. symbol for one kind of use, plus documentation for its meaning when used
  649. in this way.  Thus, when you define a symbol as a variable, you can
  650. supply an initial value for the variable, plus documentation for the
  651. variable.
  652.  
  653.    `defvar' and `defconst' are special forms that define a symbol as a
  654. global variable.  They are documented in detail in *Note Defining
  655. Variables::.
  656.  
  657.    `defun' defines a symbol as a function, creating a lambda expression
  658. and storing it in the function cell of the symbol.  This lambda
  659. expression thus becomes the function definition of the symbol.  (The
  660. term "function definition", meaning the contents of the function cell,
  661. is derived from the idea that `defun' gives the symbol its definition
  662. as a function.)  `defsubst', `define-function' and `defalias' are other
  663. ways of defining a function.  *Note Functions::.
  664.  
  665.    `defmacro' defines a symbol as a macro.  It creates a macro object
  666. and stores it in the function cell of the symbol.  Note that a given
  667. symbol can be a macro or a function, but not both at once, because both
  668. macro and function definitions are kept in the function cell, and that
  669. cell can hold only one Lisp object at any given time.  *Note Macros::.
  670.  
  671.    In XEmacs Lisp, a definition is not required in order to use a symbol
  672. as a variable or function.  Thus, you can make a symbol a global
  673. variable with `setq', whether you define it first or not.  The real
  674. purpose of definitions is to guide programmers and programming tools.
  675. They inform programmers who read the code that certain symbols are
  676. *intended* to be used as variables, or as functions.  In addition,
  677. utilities such as `etags' and `make-docfile' recognize definitions, and
  678. add appropriate information to tag tables and the `DOC' file. *Note
  679. Accessing Documentation::.
  680.  
  681. 
  682. File: lispref.info,  Node: Creating Symbols,  Next: Symbol Properties,  Prev: Definitions,  Up: Symbols
  683.  
  684. Creating and Interning Symbols
  685. ==============================
  686.  
  687.    To understand how symbols are created in XEmacs Lisp, you must know
  688. how Lisp reads them.  Lisp must ensure that it finds the same symbol
  689. every time it reads the same set of characters.  Failure to do so would
  690. cause complete confusion.
  691.  
  692.    When the Lisp reader encounters a symbol, it reads all the characters
  693. of the name.  Then it "hashes" those characters to find an index in a
  694. table called an "obarray".  Hashing is an efficient method of looking
  695. something up.  For example, instead of searching a telephone book cover
  696. to cover when looking up Jan Jones, you start with the J's and go from
  697. there.  That is a simple version of hashing.  Each element of the
  698. obarray is a "bucket" which holds all the symbols with a given hash
  699. code; to look for a given name, it is sufficient to look through all
  700. the symbols in the bucket for that name's hash code.
  701.  
  702.    If a symbol with the desired name is found, the reader uses that
  703. symbol.  If the obarray does not contain a symbol with that name, the
  704. reader makes a new symbol and adds it to the obarray.  Finding or adding
  705. a symbol with a certain name is called "interning" it, and the symbol
  706. is then called an "interned symbol".
  707.  
  708.    Interning ensures that each obarray has just one symbol with any
  709. particular name.  Other like-named symbols may exist, but not in the
  710. same obarray.  Thus, the reader gets the same symbols for the same
  711. names, as long as you keep reading with the same obarray.
  712.  
  713.    No obarray contains all symbols; in fact, some symbols are not in any
  714. obarray.  They are called "uninterned symbols".  An uninterned symbol
  715. has the same four cells as other symbols; however, the only way to gain
  716. access to it is by finding it in some other object or as the value of a
  717. variable.
  718.  
  719.    In XEmacs Lisp, an obarray is actually a vector.  Each element of the
  720. vector is a bucket; its value is either an interned symbol whose name
  721. hashes to that bucket, or 0 if the bucket is empty.  Each interned
  722. symbol has an internal link (invisible to the user) to the next symbol
  723. in the bucket.  Because these links are invisible, there is no way to
  724. find all the symbols in an obarray except using `mapatoms' (below).
  725. The order of symbols in a bucket is not significant.
  726.  
  727.    In an empty obarray, every element is 0, and you can create an
  728. obarray with `(make-vector LENGTH 0)'.  *This is the only valid way to
  729. create an obarray.*  Prime numbers as lengths tend to result in good
  730. hashing; lengths one less than a power of two are also good.
  731.  
  732.    *Do not try to put symbols in an obarray yourself.*  This does not
  733. work--only `intern' can enter a symbol in an obarray properly.  *Do not
  734. try to intern one symbol in two obarrays.*  This would garble both
  735. obarrays, because a symbol has just one slot to hold the following
  736. symbol in the obarray bucket.  The results would be unpredictable.
  737.  
  738.    It is possible for two different symbols to have the same name in
  739. different obarrays; these symbols are not `eq' or `equal'.  However,
  740. this normally happens only as part of the abbrev mechanism (*note
  741. Abbrevs::.).
  742.  
  743.      Common Lisp note: In Common Lisp, a single symbol may be interned
  744.      in several obarrays.
  745.  
  746.    Most of the functions below take a name and sometimes an obarray as
  747. arguments.  A `wrong-type-argument' error is signaled if the name is
  748. not a string, or if the obarray is not a vector.
  749.  
  750.  - Function: symbol-name SYMBOL
  751.      This function returns the string that is SYMBOL's name.  For
  752.      example:
  753.  
  754.           (symbol-name 'foo)
  755.                => "foo"
  756.  
  757.      Changing the string by substituting characters, etc, does change
  758.      the name of the symbol, but fails to update the obarray, so don't
  759.      do it!
  760.  
  761.  - Function: make-symbol NAME
  762.      This function returns a newly-allocated, uninterned symbol whose
  763.      name is NAME (which must be a string).  Its value and function
  764.      definition are void, and its property list is `nil'.  In the
  765.      example below, the value of `sym' is not `eq' to `foo' because it
  766.      is a distinct uninterned symbol whose name is also `foo'.
  767.  
  768.           (setq sym (make-symbol "foo"))
  769.                => foo
  770.           (eq sym 'foo)
  771.                => nil
  772.  
  773.  - Function: intern NAME &optional OBARRAY
  774.      This function returns the interned symbol whose name is NAME.  If
  775.      there is no such symbol in the obarray OBARRAY, `intern' creates a
  776.      new one, adds it to the obarray, and returns it.  If OBARRAY is
  777.      omitted, the value of the global variable `obarray' is used.
  778.  
  779.           (setq sym (intern "foo"))
  780.                => foo
  781.           (eq sym 'foo)
  782.                => t
  783.           
  784.           (setq sym1 (intern "foo" other-obarray))
  785.                => foo
  786.           (eq sym 'foo)
  787.                => nil
  788.  
  789.  - Function: intern-soft NAME &optional OBARRAY
  790.      This function returns the symbol in OBARRAY whose name is NAME, or
  791.      `nil' if OBARRAY has no symbol with that name.  Therefore, you can
  792.      use `intern-soft' to test whether a symbol with a given name is
  793.      already interned.  If OBARRAY is omitted, the value of the global
  794.      variable `obarray' is used.
  795.  
  796.           (intern-soft "frazzle")        ; No such symbol exists.
  797.                => nil
  798.           (make-symbol "frazzle")        ; Create an uninterned one.
  799.                => frazzle
  800.           (intern-soft "frazzle")        ; That one cannot be found.
  801.                => nil
  802.  
  803.           (setq sym (intern "frazzle"))  ; Create an interned one.
  804.                => frazzle
  805.  
  806.           (intern-soft "frazzle")        ; That one can be found!
  807.                => frazzle
  808.  
  809.           (eq sym 'frazzle)              ; And it is the same one.
  810.                => t
  811.  
  812.  - Variable: obarray
  813.      This variable is the standard obarray for use by `intern' and
  814.      `read'.
  815.  
  816.  - Function: mapatoms FUNCTION &optional OBARRAY
  817.      This function calls FUNCTION for each symbol in the obarray
  818.      OBARRAY.  It returns `nil'.  If OBARRAY is omitted, it defaults to
  819.      the value of `obarray', the standard obarray for ordinary symbols.
  820.  
  821.           (setq count 0)
  822.                => 0
  823.           (defun count-syms (s)
  824.             (setq count (1+ count)))
  825.                => count-syms
  826.           (mapatoms 'count-syms)
  827.                => nil
  828.           count
  829.                => 1871
  830.  
  831.      See `documentation' in *Note Accessing Documentation::, for another
  832.      example using `mapatoms'.
  833.  
  834.  - Function: unintern SYMBOL &optional OBARRAY
  835.      This function deletes SYMBOL from the obarray OBARRAY.  If
  836.      `symbol' is not actually in the obarray, `unintern' does nothing.
  837.      If OBARRAY is `nil', the current obarray is used.
  838.  
  839.      If you provide a string instead of a symbol as SYMBOL, it stands
  840.      for a symbol name.  Then `unintern' deletes the symbol (if any) in
  841.      the obarray which has that name.  If there is no such symbol,
  842.      `unintern' does nothing.
  843.  
  844.      If `unintern' does delete a symbol, it returns `t'.  Otherwise it
  845.      returns `nil'.
  846.  
  847. 
  848. File: lispref.info,  Node: Symbol Properties,  Prev: Creating Symbols,  Up: Symbols
  849.  
  850. Symbol Properties
  851. =================
  852.  
  853.    A "property list" ("plist" for short) is a list of paired elements
  854. stored in the property list cell of a symbol.  Each of the pairs
  855. associates a property name (usually a symbol) with a property or value.
  856. Property lists are generally used to record information about a
  857. symbol, such as its documentation as a variable, the name of the file
  858. where it was defined, or perhaps even the grammatical class of the
  859. symbol (representing a word) in a language-understanding system.
  860.  
  861.    Many objects other than symbols can have property lists associated
  862. with them, and XEmacs provides a full complement of functions for
  863. working with property lists.  *Note Property Lists::.
  864.  
  865.    The property names and values in a property list can be any Lisp
  866. objects, but the names are usually symbols.  They are compared using
  867. `eq'.  Here is an example of a property list, found on the symbol
  868. `progn' when the compiler is loaded:
  869.  
  870.      (lisp-indent-function 0 byte-compile byte-compile-progn)
  871.  
  872. Here `lisp-indent-function' and `byte-compile' are property names, and
  873. the other two elements are the corresponding values.
  874.  
  875. * Menu:
  876.  
  877. * Plists and Alists::           Comparison of the advantages of property
  878.                                   lists and association lists.
  879. * Symbol Plists::               Functions to access symbols' property lists.
  880. * Other Plists::                Accessing property lists stored elsewhere.
  881.  
  882. 
  883. File: lispref.info,  Node: Plists and Alists,  Next: Symbol Plists,  Up: Symbol Properties
  884.  
  885. Property Lists and Association Lists
  886. ------------------------------------
  887.  
  888.    Association lists (*note Association Lists::.) are very similar to
  889. property lists.  In contrast to association lists, the order of the
  890. pairs in the property list is not significant since the property names
  891. must be distinct.
  892.  
  893.    Property lists are better than association lists for attaching
  894. information to various Lisp function names or variables.  If all the
  895. associations are recorded in one association list, the program will need
  896. to search that entire list each time a function or variable is to be
  897. operated on.  By contrast, if the information is recorded in the
  898. property lists of the function names or variables themselves, each
  899. search will scan only the length of one property list, which is usually
  900. short.  This is why the documentation for a variable is recorded in a
  901. property named `variable-documentation'.  The byte compiler likewise
  902. uses properties to record those functions needing special treatment.
  903.  
  904.    However, association lists have their own advantages.  Depending on
  905. your application, it may be faster to add an association to the front of
  906. an association list than to update a property.  All properties for a
  907. symbol are stored in the same property list, so there is a possibility
  908. of a conflict between different uses of a property name.  (For this
  909. reason, it is a good idea to choose property names that are probably
  910. unique, such as by including the name of the library in the property
  911. name.)  An association list may be used like a stack where associations
  912. are pushed on the front of the list and later discarded; this is not
  913. possible with a property list.
  914.  
  915. 
  916. File: lispref.info,  Node: Symbol Plists,  Next: Other Plists,  Prev: Plists and Alists,  Up: Symbol Properties
  917.  
  918. Property List Functions for Symbols
  919. -----------------------------------
  920.  
  921.  - Function: symbol-plist SYMBOL
  922.      This function returns the property list of SYMBOL.
  923.  
  924.  - Function: setplist SYMBOL PLIST
  925.      This function sets SYMBOL's property list to PLIST.  Normally,
  926.      PLIST should be a well-formed property list, but this is not
  927.      enforced.
  928.  
  929.           (setplist 'foo '(a 1 b (2 3) c nil))
  930.                => (a 1 b (2 3) c nil)
  931.           (symbol-plist 'foo)
  932.                => (a 1 b (2 3) c nil)
  933.  
  934.      For symbols in special obarrays, which are not used for ordinary
  935.      purposes, it may make sense to use the property list cell in a
  936.      nonstandard fashion; in fact, the abbrev mechanism does so (*note
  937.      Abbrevs::.).
  938.  
  939.  - Function: get SYMBOL PROPERTY
  940.      This function finds the value of the property named PROPERTY in
  941.      SYMBOL's property list.  If there is no such property, `nil' is
  942.      returned.  Thus, there is no distinction between a value of `nil'
  943.      and the absence of the property.
  944.  
  945.      The name PROPERTY is compared with the existing property names
  946.      using `eq', so any object is a legitimate property.
  947.  
  948.      See `put' for an example.
  949.  
  950.  - Function: put SYMBOL PROPERTY VALUE
  951.      This function puts VALUE onto SYMBOL's property list under the
  952.      property name PROPERTY, replacing any previous property value.
  953.      The `put' function returns VALUE.
  954.  
  955.           (put 'fly 'verb 'transitive)
  956.                =>'transitive
  957.           (put 'fly 'noun '(a buzzing little bug))
  958.                => (a buzzing little bug)
  959.           (get 'fly 'verb)
  960.                => transitive
  961.           (symbol-plist 'fly)
  962.                => (verb transitive noun (a buzzing little bug))
  963.  
  964. 
  965. File: lispref.info,  Node: Other Plists,  Prev: Symbol Plists,  Up: Symbol Properties
  966.  
  967. Property Lists Outside Symbols
  968. ------------------------------
  969.  
  970.    These functions are useful for manipulating property lists that are
  971. stored in places other than symbols:
  972.  
  973.  - Function: getf PLIST PROPERTY &optional DEFAULT
  974.      This returns the value of the PROPERTY property stored in the
  975.      property list PLIST.  For example,
  976.  
  977.           (getf '(foo 4) 'foo)
  978.                => 4
  979.  
  980.  - Function: putf PLIST PROPERTY VALUE
  981.      This stores VALUE as the value of the PROPERTY property in the
  982.      property list PLIST.  It may modify PLIST destructively, or it may
  983.      construct a new list structure without altering the old.  The
  984.      function returns the modified property list, so you can store that
  985.      back in the place where you got PLIST.  For example,
  986.  
  987.           (setq my-plist '(bar t foo 4))
  988.                => (bar t foo 4)
  989.           (setq my-plist (putf my-plist 'foo 69))
  990.                => (bar t foo 69)
  991.           (setq my-plist (putf my-plist 'quux '(a)))
  992.                => (quux (a) bar t foo 5)
  993.  
  994.  - Function: plists-eq A B
  995.      This function returns non-`nil' if property lists A and B are
  996.      `eq'.  This means that the property lists have the same values for
  997.      all the same properties, where comparison between values is done
  998.      using `eq'.
  999.  
  1000.  - Function: plists-equal A B
  1001.      This function returns non-`nil' if property lists A and B are
  1002.      `equal'.
  1003.  
  1004.    Both of the above functions do order-insensitive comparisons.
  1005.  
  1006.      (plists-eq '(a 1 b 2 c nil) '(b 2 a 1))
  1007.           => t
  1008.      (plists-eq '(foo "hello" bar "goodbye") '(bar "goodbye" foo "hello"))
  1009.           => nil
  1010.      (plists-equal '(foo "hello" bar "goodbye") '(bar "goodbye" foo "hello"))
  1011.           => t
  1012.  
  1013. 
  1014. File: lispref.info,  Node: Evaluation,  Next: Control Structures,  Prev: Symbols,  Up: Top
  1015.  
  1016. Evaluation
  1017. **********
  1018.  
  1019.    The "evaluation" of expressions in XEmacs Lisp is performed by the
  1020. "Lisp interpreter"--a program that receives a Lisp object as input and
  1021. computes its "value as an expression".  How it does this depends on the
  1022. data type of the object, according to rules described in this chapter.
  1023. The interpreter runs automatically to evaluate portions of your
  1024. program, but can also be called explicitly via the Lisp primitive
  1025. function `eval'.
  1026.  
  1027. * Menu:
  1028.  
  1029. * Intro Eval::  Evaluation in the scheme of things.
  1030. * Eval::        How to invoke the Lisp interpreter explicitly.
  1031. * Forms::       How various sorts of objects are evaluated.
  1032. * Quoting::     Avoiding evaluation (to put constants in the program).
  1033.  
  1034. 
  1035. File: lispref.info,  Node: Intro Eval,  Next: Eval,  Up: Evaluation
  1036.  
  1037. Introduction to Evaluation
  1038. ==========================
  1039.  
  1040.    The Lisp interpreter, or evaluator, is the program that computes the
  1041. value of an expression that is given to it.  When a function written in
  1042. Lisp is called, the evaluator computes the value of the function by
  1043. evaluating the expressions in the function body.  Thus, running any
  1044. Lisp program really means running the Lisp interpreter.
  1045.  
  1046.    How the evaluator handles an object depends primarily on the data
  1047. type of the object.
  1048.  
  1049.    A Lisp object that is intended for evaluation is called an
  1050. "expression" or a "form".  The fact that expressions are data objects
  1051. and not merely text is one of the fundamental differences between
  1052. Lisp-like languages and typical programming languages.  Any object can
  1053. be evaluated, but in practice only numbers, symbols, lists and strings
  1054. are evaluated very often.
  1055.  
  1056.    It is very common to read a Lisp expression and then evaluate the
  1057. expression, but reading and evaluation are separate activities, and
  1058. either can be performed alone.  Reading per se does not evaluate
  1059. anything; it converts the printed representation of a Lisp object to the
  1060. object itself.  It is up to the caller of `read' whether this object is
  1061. a form to be evaluated, or serves some entirely different purpose.
  1062. *Note Input Functions::.
  1063.  
  1064.    Do not confuse evaluation with command key interpretation.  The
  1065. editor command loop translates keyboard input into a command (an
  1066. interactively callable function) using the active keymaps, and then
  1067. uses `call-interactively' to invoke the command.  The execution of the
  1068. command itself involves evaluation if the command is written in Lisp,
  1069. but that is not a part of command key interpretation itself.  *Note
  1070. Command Loop::.
  1071.  
  1072.    Evaluation is a recursive process.  That is, evaluation of a form may
  1073. call `eval' to evaluate parts of the form.  For example, evaluation of
  1074. a function call first evaluates each argument of the function call, and
  1075. then evaluates each form in the function body.  Consider evaluation of
  1076. the form `(car x)': the subform `x' must first be evaluated
  1077. recursively, so that its value can be passed as an argument to the
  1078. function `car'.
  1079.  
  1080.    Evaluation of a function call ultimately calls the function specified
  1081. in it.  *Note Functions::.  The execution of the function may itself
  1082. work by evaluating the function definition; or the function may be a
  1083. Lisp primitive implemented in C, or it may be a byte-compiled function
  1084. (*note Byte Compilation::.).
  1085.  
  1086.    The evaluation of forms takes place in a context called the
  1087. "environment", which consists of the current values and bindings of all
  1088. Lisp variables.(1)  Whenever the form refers to a variable without
  1089. creating a new binding for it, the value of the binding in the current
  1090. environment is used.  *Note Variables::.
  1091.  
  1092.    Evaluation of a form may create new environments for recursive
  1093. evaluation by binding variables (*note Local Variables::.).  These
  1094. environments are temporary and vanish by the time evaluation of the form
  1095. is complete.  The form may also make changes that persist; these changes
  1096. are called "side effects".  An example of a form that produces side
  1097. effects is `(setq foo 1)'.
  1098.  
  1099.    The details of what evaluation means for each kind of form are
  1100. described below (*note Forms::.).
  1101.  
  1102.    ---------- Footnotes ----------
  1103.  
  1104.    (1) This definition of "environment" is specifically not intended to
  1105. include all the data that can affect the result of a program.
  1106.  
  1107. 
  1108. File: lispref.info,  Node: Eval,  Next: Forms,  Prev: Intro Eval,  Up: Evaluation
  1109.  
  1110. Eval
  1111. ====
  1112.  
  1113.    Most often, forms are evaluated automatically, by virtue of their
  1114. occurrence in a program being run.  On rare occasions, you may need to
  1115. write code that evaluates a form that is computed at run time, such as
  1116. after reading a form from text being edited or getting one from a
  1117. property list.  On these occasions, use the `eval' function.
  1118.  
  1119.    *Note:* it is generally cleaner and more flexible to call functions
  1120. that are stored in data structures, rather than to evaluate expressions
  1121. stored in data structures.  Using functions provides the ability to
  1122. pass information to them as arguments.
  1123.  
  1124.    The functions and variables described in this section evaluate forms,
  1125. specify limits to the evaluation process, or record recently returned
  1126. values.  Loading a file also does evaluation (*note Loading::.).
  1127.  
  1128.  - Function: eval FORM
  1129.      This is the basic function for performing evaluation.  It evaluates
  1130.      FORM in the current environment and returns the result.  How the
  1131.      evaluation proceeds depends on the type of the object (*note
  1132.      Forms::.).
  1133.  
  1134.      Since `eval' is a function, the argument expression that appears
  1135.      in a call to `eval' is evaluated twice: once as preparation before
  1136.      `eval' is called, and again by the `eval' function itself.  Here
  1137.      is an example:
  1138.  
  1139.           (setq foo 'bar)
  1140.                => bar
  1141.           (setq bar 'baz)
  1142.                => baz
  1143.           ;; `eval' receives argument `bar', which is the value of `foo'
  1144.           (eval foo)
  1145.                => baz
  1146.           (eval 'foo)
  1147.                => bar
  1148.  
  1149.      The number of currently active calls to `eval' is limited to
  1150.      `max-lisp-eval-depth' (see below).
  1151.  
  1152.  - Command: eval-region START END &optional STREAM
  1153.      This function evaluates the forms in the current buffer in the
  1154.      region defined by the positions START and END.  It reads forms from
  1155.      the region and calls `eval' on them until the end of the region is
  1156.      reached, or until an error is signaled and not handled.
  1157.  
  1158.      If STREAM is supplied, `standard-output' is bound to it during the
  1159.      evaluation.
  1160.  
  1161.      You can use the variable `load-read-function' to specify a function
  1162.      for `eval-region' to use instead of `read' for reading
  1163.      expressions.  *Note How Programs Do Loading::.
  1164.  
  1165.      `eval-region' always returns `nil'.
  1166.  
  1167.  - Command: eval-buffer BUFFER &optional STREAM
  1168.      This is like `eval-region' except that it operates on the whole
  1169.      contents of BUFFER.
  1170.  
  1171.  - Variable: max-lisp-eval-depth
  1172.      This variable defines the maximum depth allowed in calls to `eval',
  1173.      `apply', and `funcall' before an error is signaled (with error
  1174.      message `"Lisp nesting exceeds max-lisp-eval-depth"').  This counts
  1175.      internal uses of those functions, such as for calling the functions
  1176.      mentioned in Lisp expressions, and recursive evaluation of
  1177.      function call arguments and function body forms.
  1178.  
  1179.      This limit, with the associated error when it is exceeded, is one
  1180.      way that Lisp avoids infinite recursion on an ill-defined function.
  1181.  
  1182.      The default value of this variable is 200.  If you set it to a
  1183.      value less than 100, Lisp will reset it to 100 if the given value
  1184.      is reached.
  1185.  
  1186.      `max-specpdl-size' provides another limit on nesting.  *Note Local
  1187.      Variables::.
  1188.  
  1189.  - Variable: values
  1190.      The value of this variable is a list of the values returned by all
  1191.      the expressions that were read from buffers (including the
  1192.      minibuffer), evaluated, and printed.  The elements are ordered
  1193.      most recent first.
  1194.  
  1195.           (setq x 1)
  1196.                => 1
  1197.           (list 'A (1+ 2) auto-save-default)
  1198.                => (A 3 t)
  1199.           values
  1200.                => ((A 3 t) 1 ...)
  1201.  
  1202.      This variable is useful for referring back to values of forms
  1203.      recently evaluated.  It is generally a bad idea to print the value
  1204.      of `values' itself, since this may be very long.  Instead, examine
  1205.      particular elements, like this:
  1206.  
  1207.           ;; Refer to the most recent evaluation result.
  1208.           (nth 0 values)
  1209.                => (A 3 t)
  1210.           ;; That put a new element on,
  1211.           ;;   so all elements move back one.
  1212.           (nth 1 values)
  1213.                => (A 3 t)
  1214.           ;; This gets the element that was next-to-most-recent
  1215.           ;;   before this example.
  1216.           (nth 3 values)
  1217.                => 1
  1218.  
  1219. 
  1220. File: lispref.info,  Node: Forms,  Next: Quoting,  Prev: Eval,  Up: Evaluation
  1221.  
  1222. Kinds of Forms
  1223. ==============
  1224.  
  1225.    A Lisp object that is intended to be evaluated is called a "form".
  1226. How XEmacs evaluates a form depends on its data type.  XEmacs has three
  1227. different kinds of form that are evaluated differently: symbols, lists,
  1228. and "all other types".  This section describes all three kinds,
  1229. starting with "all other types" which are self-evaluating forms.
  1230.  
  1231. * Menu:
  1232.  
  1233. * Self-Evaluating Forms::   Forms that evaluate to themselves.
  1234. * Symbol Forms::            Symbols evaluate as variables.
  1235. * Classifying Lists::       How to distinguish various sorts of list forms.
  1236. * Function Indirection::    When a symbol appears as the car of a list,
  1237.                   we find the real function via the symbol.
  1238. * Function Forms::          Forms that call functions.
  1239. * Macro Forms::             Forms that call macros.
  1240. * Special Forms::           "Special forms" are idiosyncratic primitives,
  1241.                               most of them extremely important.
  1242. * Autoloading::             Functions set up to load files
  1243.                               containing their real definitions.
  1244.  
  1245. 
  1246. File: lispref.info,  Node: Self-Evaluating Forms,  Next: Symbol Forms,  Up: Forms
  1247.  
  1248. Self-Evaluating Forms
  1249. ---------------------
  1250.  
  1251.    A "self-evaluating form" is any form that is not a list or symbol.
  1252. Self-evaluating forms evaluate to themselves: the result of evaluation
  1253. is the same object that was evaluated.  Thus, the number 25 evaluates to
  1254. 25, and the string `"foo"' evaluates to the string `"foo"'.  Likewise,
  1255. evaluation of a vector does not cause evaluation of the elements of the
  1256. vector--it returns the same vector with its contents unchanged.
  1257.  
  1258.      '123               ; An object, shown without evaluation.
  1259.           => 123
  1260.      123                ; Evaluated as usual--result is the same.
  1261.           => 123
  1262.      (eval '123)        ; Evaluated "by hand"--result is the same.
  1263.           => 123
  1264.      (eval (eval '123)) ; Evaluating twice changes nothing.
  1265.           => 123
  1266.  
  1267.    It is common to write numbers, characters, strings, and even vectors
  1268. in Lisp code, taking advantage of the fact that they self-evaluate.
  1269. However, it is quite unusual to do this for types that lack a read
  1270. syntax, because there's no way to write them textually.  It is possible
  1271. to construct Lisp expressions containing these types by means of a Lisp
  1272. program.  Here is an example:
  1273.  
  1274.      ;; Build an expression containing a buffer object.
  1275.      (setq buffer (list 'print (current-buffer)))
  1276.           => (print #<buffer eval.texi>)
  1277.      ;; Evaluate it.
  1278.      (eval buffer)
  1279.           -| #<buffer eval.texi>
  1280.           => #<buffer eval.texi>
  1281.  
  1282.